package com.yxlgateway.gateway.controller;

import com.yxlcommon.common.pojo.Author;
import com.yxlcommon.common.pojo.RespBean;
import com.yxlgateway.service.AuthorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: yxl
 * @since: 2021-11-22
 **/
@Slf4j
@RestController
@RequestMapping("/author")
public class AuthorController {

    @Autowired
    private AuthorService authorService;

    @PostMapping("/recommendAuthors")
    public RespBean authors(){
        return RespBean.operationSuccess("推荐成功",200,authorService.getRecommendAuthors());
    }

    @PostMapping("/getAuthorsByKeyword")
    public RespBean getAuthorsByKeyword(@RequestBody Author author){
        return RespBean.operationSuccess("搜索成功",200,authorService.selectAuthorsByKeyword(author.getUsername()));
    }

    @PostMapping("/getAllAuthors")
    public RespBean getAllAuthors(){
        return RespBean.operationSuccess("推荐成功",200,authorService.selectAllAuthors());
    }

    @PostMapping("/getAuthorByUsername")
    public RespBean<Author> getAuthorByUsername(@RequestBody Author author){
        return authorService.selectAuthorByUsername(author);
    }

    @PostMapping("/selectAuthorById")
    public RespBean<Author> selectAuthorById(@RequestBody Author author){
        return authorService.selectAuthorById(author);
    }

}
